<?php
namespace Asset\Controller;

use Base\Controller\AdminBaseController;

class UploadController extends AdminBaseController {
	
	function _initialize() {
// 		$adminid = sp_get_current_admin_id();
// 		$userid = sp_get_current_userid();
// 		if (empty($adminid) && empty($userid)) {
// 			exit("非法上传！");
// 		}
	}
	
	// 文件上传
	public function upload($savePath = '') {
		$upload = new \Think\Upload();					// 实例化上传类
		$upload->maxSize = 20 * 1024 * 1024;			// 设置附件上传大小
		$upload->exts = array(							// 设置附件上传类型
				'jpg',
				'gif',
				'png',
				'jpeg' 
		);
		$upload->rootPath = './' . C("UPLOADPATH");		// 设置附件上传根目录
		$upload->savePath = date('Ymd') . '/';          // 设置附件上传（子）目录	date('Y-m-d') . '/'
		$upload->autoSub = true;
		$upload->subName = $savePath;
		
		$info = $upload->upload();						// 上传文件
		if (!$info) {
			$data['url'] = $upload->getError();
			$this->ajaxReturn($data);
		}

		$data['url'] = C("UPLOADPATH") . $info['file']['savepath'] . $info['file']['savename'];
		$this->ajaxReturn($data);
	}
}
